#!c:/usr/perl

##########################
#     PortalCrawler      #
# Rok akademicki 2010/11 #
#     semestr zimowy     #
##########################
#    Krzysztof Ulman     #
# Politechnika Krakowska #
#    Praca Inzynierska   #
##########################

use strict;
use warnings;
use encoding 'utf8';

#version1();
version2();

#http://tools.rosinstrument.com/proxy/
sub version1 {

	open(PLIK, "lista-proxy.txt");
	
	my @infoList;
	my $id = 0;
	
	while(my $line = <PLIK>) {
		chomp $line;
		if($line =~ /^([a-z][a-z])$/i) {
			push(@infoList, $1);
		} else {
			(my $address, my $port) = split(/:/, $line);
	
			my $info = $infoList[$id];
			
			$id++;
			
			
			my $sql = 'INSERT INTO "OMNIBUS_proxies" ("address", "port", "info") VALUES (\'';
			$sql .=  $address . '\', ';
			$sql .= $port . ", \'";
			$sql .= $info . "\');";
			
			print $sql . "\n";
		}
	}
	
	close PLIK;
}

#http://multiproxy.org/all_proxy.htm
sub version2 {

	open(PLIK, "lista-proxy-2.txt");
	while(my $line = <PLIK>) {
		chomp $line;
		(my $address, my $port) = split(/:/, $line);
	
		my $sql = 'INSERT INTO "OMNIBUS_proxies" ("address", "port") VALUES (\'';
		$sql .=  $address . '\', ';
		$sql .= $port . ");";
		
		print $sql . "\n";
	}
	
	close PLIK;
}
